//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    addressList:[],
    issel:1
  },

  selectTap: function (e) {
    if(this.data.issel==0)
    {
      wx.navigateBack({})
      return;
    }
    
    var id = e.currentTarget.dataset.id;
    wx.request({
      url: app.globalData.host +'/api/user/SetDefaultAddress',
      data: {
        uid:app.globalData.userInfo.Uid,
        said:id,
        isDefault:1
      },
      success: (res) =>{
        wx.navigateBack({})
      }
    })
  },

  addAddess : function () {
    wx.redirectTo({
      url: "/pages/address-add/index?said=0"
    }) 
  },
  
  editAddess: function (e) {
    wx.redirectTo({
      url: "/pages/address-add/index?said=" + e.currentTarget.dataset.id
    })
  },
  
  onLoad: function (e) {
    console.log('onLoad');
    if(e.issel){
      this.setData({
        issel:e.issel
      })
    }
  },
  onShow : function () {
    this.initShippingAddress();
  },
  initShippingAddress: function () {
    var that = this;
    wx.request({
      url: app.globalData.host +'/api/user/GetShipAddressList',
      data: {
        uid:app.globalData.userInfo.Uid
      },
      success: (res) =>{
        if (res.data.Code == 0) {
          that.setData({
            addressList:res.data.Data
          });
        }
      }
    })
  },
  onPullDownRefresh: function () {
    // 页面相关事件处理函数--监听用户下拉动作
    wx.stopPullDownRefresh();
  }

})
